package io.github.talelin.latticy.controller.v1;

import io.github.talelin.latticy.model.MsgLogDO;
import io.github.talelin.latticy.service.MsgLogService;
import io.github.talelin.latticy.vo.CreatedVO;
import io.github.talelin.latticy.vo.DeletedVO;
import io.github.talelin.latticy.vo.PageResponseVO;
import io.github.talelin.latticy.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;

/**
 * 消息投递日志前端控制器
 *
 * @author generator@wulongbo
 * @since 2022-07-22
 */
@RestController
@RequestMapping("/v1/msg-log")
public class MsgLogController {

    @Autowired
    private MsgLogService msgLogService;

    @PostMapping("/create")
    public CreatedVO create(@RequestBody MsgLogDO msgLogDO) {
        msgLogService.createMsgLog(msgLogDO);
        return new CreatedVO();
    }

    @PostMapping("/update")
    public void updateById(@RequestBody MsgLogDO msgLogDO) {
        msgLogService.updateMsgLogById(msgLogDO);
    }

    @PutMapping("/{id}")
    public UpdatedVO update(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new UpdatedVO();
    }

    @DeleteMapping("/{id}")
    public DeletedVO delete(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return new DeletedVO();
    }

    @GetMapping("/{id}")
    public MsgLogDO get(@PathVariable(value = "id") @Positive(message = "{id.positive}") Long id) {
        return msgLogService.getMsgLogById(id);
    }

    @GetMapping("/page")
    public PageResponseVO<MsgLogDO> page(
            @RequestParam(name = "page", required = false, defaultValue = "0")
            @Min(value = 0, message = "{page.number.min}") Integer page,
            @RequestParam(name = "count", required = false, defaultValue = "10")
            @Min(value = 1, message = "{page.count.min}")
            @Max(value = 30, message = "{page.count.max}") Integer count
    ) {
        return null;
    }

}
